package com.mhkj.workspace.notify.controller;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mhkj.workspace.notify.entity.Notify;
import com.mhkj.workspace.notify.service.NotifyService;
import com.mics.core.common.componet.JsonHandler;
import com.mics.core.common.componet.Pagination;
import com.mics.core.common.componet.ResponseMessage;
import com.mics.core.system.base.controller.BaseController;

@Controller
@RequestMapping("/notify")
public class NotifyController extends BaseController<Notify> {

    @Resource
    private NotifyService notifyService;
    @Resource
    private JsonHandler jsonHandler;

    @InitBinder
    protected void init(HttpServletRequest request, ServletRequestDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
    }

    @Resource
    public void setNotifyService(NotifyService notifyService) {
        super.setBaseService(notifyService);
    }
//预警状态   6,7  汇报  3   待办 1 考核 5
    //预警通知
    @RequestMapping("/listByPage")
    @ResponseBody
    public void listByPage(HttpServletResponse response, Notify notify, int pageIndex, int pageSize) {
       // notify.setType(6);
        Pagination<Notify> list = notifyService.listByPage(notify, pageIndex, pageSize);
        jsonHandler.sendJsonString(response, true, "获取数据成功", list,
                new String[]{"id", "sName", "createDate", "method", "content","estate","planNode.id"},
                new String[]{"id", "sName", "createDate", "method", "content","estate","planNode"});
    }
    @RequestMapping(value="/listByPage1", method=RequestMethod.POST)
    @ResponseBody
    public void listByPage1(HttpServletResponse response, Notify notify, int pageIndex, int pageSize) {
        // notify.setType(6);
        Pagination<Notify> list = notifyService.listByPage(notify, pageIndex, pageSize);
        jsonHandler.sendJsonString(response, true, "获取数据成功", list,
                new String[]{"id", "sName", "createDate", "method", "content","estate","planNode.id"},
                new String[]{"id", "sName", "createDate", "method", "content","estate","planNode"});
    }
    //汇报通知
    @RequestMapping("/affectedListByPage")
    @ResponseBody
    public void affectedListByPage(HttpServletResponse response, Notify notify, int pageIndex, int pageSize) {
        // Pagination<Notify> pagination = new Pagination<>();

        Pagination<Notify> list = notifyService.affectedListByPage(notify, pageIndex, pageSize);
        jsonHandler.sendJsonString(response, true, "获取数据成功", list,
                new String[]{"id", "sName", "createDate", "method", "content","estate","planNode.id"},
                new String[]{"id", "sName", "createDate", "method", "content","estate","planNode"});
    }
    //汇报通知
    @RequestMapping(value = "/affectedListByPage1", method=RequestMethod.POST)
    @ResponseBody
    public void affectedListByPage1(HttpServletResponse response, Notify notify, int pageIndex, int pageSize) {
        // Pagination<Notify> pagination = new Pagination<>();

        Pagination<Notify> list = notifyService.affectedListByPage(notify, pageIndex, pageSize);
        jsonHandler.sendJsonString(response, true, "获取数据成功", list,
                new String[]{"id", "sName", "createDate", "method", "content","estate","planNode.id"},
                new String[]{"id", "sName", "createDate", "method", "content","estate","planNode"});
    }
    //考核通知
    @RequestMapping("/needListByPage")
    @ResponseBody
    public void needListByPage(HttpServletResponse response, Notify notify, int pageIndex, int pageSize) {
        // Pagination<Notify> pagination = new Pagination<>();

        Pagination<Notify> list = notifyService.needListByPage(notify, pageIndex, pageSize);
        jsonHandler.sendJsonString(response, true, "获取数据成功", list,
                new String[]{"id", "sName", "createDate", "method", "content", "editDate", "type","estate","planNode.id"},
                new String[]{"id", "sName", "createDate", "method", "content", "editDate", "type","estate","planNode"});
    }

    //考核通知
    @RequestMapping(value="/needListByPage1", method=RequestMethod.POST)
    @ResponseBody
    public void needListByPage1(HttpServletResponse response, Notify notify,int pageIndex, int pageSize) {

        Pagination<Notify> list = notifyService.needListByPage(notify, pageIndex, pageSize);

        jsonHandler.sendJsonString(response, true, "获取数据成功", list,
                new String[]{"id", "sName", "createDate", "method", "content", "editDate", "type","estate","planNode.id"},
                new String[]{"id", "sName", "createDate", "method", "content", "editDate", "type","estate","planNode"});
    }
    //待办通知
    @RequestMapping("/confirmListByPage")
    @ResponseBody
    public void confirmListByPage(HttpServletResponse response, Notify notify, int pageIndex, int pageSize) {
        Pagination<Notify> list = notifyService.confirmListByPage(notify, pageIndex, pageSize);
        jsonHandler.sendJsonString(response, true, "获取数据成功", list,
                new String[]{"id", "sName", "createDate", "method", "content", "type","estate","planNode.id"},
                new String[]{"id", "sName", "createDate", "method", "content", "type","estate","planNode"});
    }

    //待办通知
    @RequestMapping(value = "/confirmListByPage1", method=RequestMethod.POST)
    @ResponseBody
    public void confirmListByPage1(HttpServletResponse response, Notify notify, int pageIndex, int pageSize) {
        Pagination<Notify> list = notifyService.confirmListByPage(notify, pageIndex, pageSize);
        jsonHandler.sendJsonString(response, true, "获取数据成功", list,
                new String[]{"id", "sName", "createDate", "method", "content", "type","estate","planNode.id"},
                new String[]{"id", "sName", "createDate", "method", "content", "type","estate","planNode"});
    }


    @RequestMapping(value="/edit", method=RequestMethod.POST)
    @ResponseBody
    public ResponseMessage edit(Notify notify) {
        Notify notify1=notifyService.getById(notify.getId());

        notify1.setEstate(1);
        System.out.println(notify1);

        String message = notifyService.edit(notify1);
        return ResponseMessage.createMessage("ok".equals(message), message);
    }
    /**
     * 删除
     */
    @RequestMapping(value="/del", method= RequestMethod.POST)
    @ResponseBody
    public ResponseMessage del(Notify y) {
        String message = notifyService.del(y);
        return ResponseMessage.createMessage("ok".equals(message), message);
    }

}